import json

from scene._car_config import Car_config


def parse_route(rou_cfg):
    """
        解析json路由规则
        return: 不同事件的路由规则
    """
    # 解析路由规则 事件初始化
    accident = list()
    rateLimiting = list()
    rampControl = dict()
    emergencyLane = list()
    specialLane = list()
    platoonSwitch = dict()
    car_config = list()
    if rou_cfg is not None:
        sceneInfo = rou_cfg['sceneInfo']
        # 施工区域
        if 'accident' in sceneInfo:
            accident = sceneInfo['accident']
        # 主路限速
        if 'rateLimiting' in sceneInfo:
            rateLimiting = sceneInfo['rateLimiting']
        # 匝道管控
        if 'rampControl' in sceneInfo:
            rampControl = sceneInfo['rampControl']
        # 应急车道
        if 'emergencyLane' in sceneInfo:
            emergencyLane = sceneInfo['emergencyLane']
        # 专用车道
        if 'specialLane' in sceneInfo:
            specialLane = sceneInfo['specialLane']
        # 编队车辆
        if 'platoonSwitch' in sceneInfo:
            platoonSwitch = sceneInfo['platoonSwitch']
        # 恶劣天气
        if 'badWeather' in sceneInfo:
            badWeather = sceneInfo['badWeather']
        if 'route' in rou_cfg:
            car_config = rou_cfg['route']
            car_config_list=list()
            if car_config is not None and len(car_config) > 0:
                for i in range(len(car_config)):
                    car_config_init = Car_config.from_json(car_config[i])
                    car_config_list.append(car_config_init)
    return accident, rateLimiting, rampControl, emergencyLane, specialLane, platoonSwitch,badWeather, car_config_list

